#pragma once
#include "baidu_aip_cpp/speech.h"
#include "logger.hpp"

class Spe_Client
{
private:
    aip::Speech _client;

public:
    using ptr = std::shared_ptr<Spe_Client>;
    Spe_Client(const std::string &app_id,
               const std::string &api_key,
               const std::string &secret_key)
        : _client(app_id, api_key, secret_key)
    {
    }

    std::string Recognition(const std::string &spe_date)
    {
        Json::Value result = _client.recognize(spe_date, "pcm", 16000, aip::null);
        if (result["err_no"].asInt() != 0)
        {
            LOG_ERROR("语音识别失败: {}", result["err_msg"].asString());
            return std::string();
        }
        return result["result"][0].asString();
    }
};